<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="/WEB-INF/views/import.jsp" flush="true" />
<%
	String path = request.getContextPath();
	String width = "180";
%>


</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					
					<div class="caption">
						<span class="title">销户信息</span>
					</div>

					<div class="fieldBox col_50">
						<div class="label">销户日期</div>
						<div class="field">
							<input id="accountCloseDate" name="accountCloseDate" type="text"
								ligerui="width: <%=width%>" class="ui-datepicker"
								value="${fncGroupCompanyAccountVO.accountCloseDate}" />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label"></div>
						<div class="field"></div>
					</div>


					<c:if test="${ flowType == 'closeAccount'}">
						<div class="caption">
							<span class="title">销户申请信息</span>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人</div>
							<div class="field">
								<input id="applCancelUsrNm" name="applCancelUsrNm" type="text"
									class="ui-textbox" ligerui="width: <%=width%>"
									disabled="disabled"
									value="${fncGroupCompanyAccountVO.applCancelUsrNm}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请日期</div>
							<div class="field">
								<input id="applCancelDate" name="applCancelDate" type="text"
									disabled="disabled" ligerui="width: <%=width%>"
									class="ui-datepicker"
									value="${fncGroupCompanyAccountVO.applCancelDate}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人所属部门</div>
							<div class="field">
								<input id="applCancelOrg" name="applCancelOrg" type="text"
									class="ui-textbox" ligerui="width: <%=width%>"
									disabled="disabled"
									value="${fncGroupCompanyAccountVO.applCancelOrg}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人电话</div>
							<div class="field">
								<input id="applCancelPhone" name="applCancelPhone" type="text"
									class="ui-textbox" ligerui="width: <%=width%>"
									validate="{required:true,mobile:true}"
									value="${fncGroupCompanyAccountVO.applCancelPhone}" />
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">申请原因</div>
							<div class="field">
								<input id="applCancelReason" name="applCancelReason" type="text"
									class="ui-textbox" ligerui="width: <%=width%>"
									validate="{required:true}"
									value="${fncGroupCompanyAccountVO.applCancelReason}" />
							</div>
						</div>

						<!-- 附件显示 -->
						<div class="fieldBox col_100">
							<div style="width: 98%; margin-left: 1%;">
								<jsp:include page="../../rfbuss/frCommFilesList.jsp"
									flush="true"></jsp:include>
								<div id="ligergrid_file1" class="sq-grid"></div>
							</div>
						</div>

					</c:if>

					<div class="btnsBox">

						<c:if test="${operate == 'initiatorUpdate'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('initiatorUpdate');">保存</span>
						</c:if>
						<c:if test="${operate == 'updateOpenAccount'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('updateOpenAccount');">修改开户保存</span>
						</c:if>
						<c:if test="${operate == 'confirmAccountCancel'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('confirmAccountCancel');">保存</span>
						</c:if>
						<c:if test="${operate == 'updateAll'}">
							<span id="saveBtn" class="sq-button sq-button-round"
								onclick="save('updateAll');">保存</span>
						</c:if>
					</div>
					<div class="fieldBox col_100" style="display: none;">
						<div class="field">
							<input name="sysDate" id="sysDate" type="text" class="ui-textbox"
								value="${sysDate }"> <input name="loginUsrNm"
								id="loginUsrNm" type="text" class="ui-textbox"
								value="${loginUsrNm }">
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	     
		$(function() {
			$("#ligerForm").ligerForm({
		        validate : true
		    });
			
	        
	        
	     <c:if test="${flowType == 'closeAccount'}">
	    		//销户流程
	    	<c:if test="${operate == 'initiatorUpdate'}">
	    		//发起人修改
	        	setCloseAccountDisabled();
	        </c:if>
	        <c:if test="${operate == 'view' || operate == 'confirmAccountCancel'}">
	        	//查看:都不可修改
	        	setTopDisabled();
	        	setOpenAccountInfoDisabled();
	        	setCloseAccountDisabled();
	        </c:if>
	    </c:if>
        
		<c:if test="${flowType == 'closeAccount'}">
	    	//销户申请附件列表
	    	loadFilesLiger("closeAccount", 1, "${fncGroupCompanyAccountVO.id}", "no");
		</c:if>
	
	    });
		
		//上半部分不可用
		function setTopDisabled(){
			
			<c:if test="${operate != 'confirmAccountCancel'}">
	        	//确认账户已注销:填写销户日期
	        	liger.get("accountCloseDate").setDisabled(true);
	        </c:if>
			
		}
		//开户信息不可用
		function setOpenAccountInfoDisabled(){
			
		}
		
		
		//开户字段不可用
		function setOpenAccountDisabled(){
		}
		
		//销户字段不可用
		function setCloseAccountDisabled(){
			liger.get("applCancelUsrNm").setDisabled(true);
			liger.get("applCancelDate").setDisabled(true);
			liger.get("applCancelOrg").setDisabled(true);
			liger.get("applCancelPhone").setDisabled(true);
			liger.get("applCancelReason").setDisabled(true);
		}
		
		
		function save(operate){
			
			//验证
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
		            return ; 
		     }
			/*if($.trim($("#idCard").val()) == ""){
					$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning",SQ_showButtons: true});
					return ;
			} */ 
		   //填写开户信息
		   if(operate=='updateOpenAccount' || operate=='updateAll'){//校验开户信息必填项
			  var corpName=$('#corpName').val();//法人姓名
			  var corpPhone=$('#corpPhone').val();//法人预留电话
			  var operName=$('#operName').val();//经办人姓名	
			  var operPhone=$('#operPhone').val();// 经办人预留电话
			  if($.trim(corpName)==''){
					$.ligerDialog.SQalert({content: "请填写法人姓名!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(corpPhone)==''){
					$.ligerDialog.SQalert({content: "请填写法人预留电话!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(operName)==''){
					$.ligerDialog.SQalert({content: "请填写经办人姓名!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  if($.trim(operPhone)==''){
					$.ligerDialog.SQalert({content: "请填写经办人预留电话!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
			  //校验开户资料必填项
			  var ligergrid_file2=liger.get("ligergrid_file2");
			  var gridFile=ligergrid_file2.getData();
			  if (Object.keys(gridFile).length == 0) {
				  $.ligerDialog.SQalert({content: "请上传开户资料!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			  }
		   }//end by 校验开户信息必填项
		   
			//组织数据，提交后台
			var data = ligerForm.getData();
				
			data["id"] = "${fncGroupCompanyAccountVO.id}";
			data["bankProv"] = data.rgnProvCd;//开户地-省
			data["bankCity"] = data.rgnCityCd;//开户地-市
			
			data["applUsrId"] = "${fncGroupCompanyAccountVO.applUsrId}";
			data["applOrgCd"] = "${fncGroupCompanyAccountVO.applOrgCd}";
			
			data["applCancelUsrId"] = "${fncGroupCompanyAccountVO.applCancelUsrId}";
			data["applCancelOrgCd"] = "${fncGroupCompanyAccountVO.applCancelOrgCd}";
			
			console.log(data);
			//return;
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/account/fncGroupCompanyAccount/save.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						alert(msg.info);
						//saveFile2('${fncGroupCompanyAccountVO.id}');
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
	//申请人确认邮寄 节点需填写“邮寄信息 运营专员确认接收  财务出纳确认接收
	function updatePostBtn(tabFlag){
		
		var handWay=$('#handWay').val();//交接方式
		var postInfo=$('#postInfo').val();//邮寄快递及单号
		var receiver=$('#receiver').val();//接收人
		var postData=$('#postData').val();//邮寄资料
		var onlineBankNum=$('#onlineBankNum').val();//网银数量
		var onlineBankSingle=$('#onlineBankSingle').val();//网银制单人
		var onlineBankReviewer=$('#onlineBankReviewer').val();//网银复核人
		
		if(tabFlag=='101'){//申请人确认邮寄 节点需填写“邮寄信息
			if($.trim(handWay)==''){
				$.ligerDialog.SQalert({content: "请填写交接方式!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if(handWay==2){
				if($.trim(postInfo)==''){
					$.ligerDialog.SQalert({content: "请填写邮寄快递及单号!",SQ_type: "warning",SQ_showButtons: true});
					return ;
				}
			}
			if($.trim(receiver)==''){
				$.ligerDialog.SQalert({content: "请填写接收人!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if($.trim(postData)==''){
				$.ligerDialog.SQalert({content: "请填写邮寄资料!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
			if($.trim(onlineBankNum)==''){
				$.ligerDialog.SQalert({content: "请填写网银数量!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
		}//end tabFlag=101
	  	if(tabFlag=='102'){//运营专员确认接收
		 	if($.trim(onlineBankReviewer)==''){
				$.ligerDialog.SQalert({content: "请填写网银复核人!",SQ_type: "warning",SQ_showButtons: true});
				return ;
			}
	  	}	
	 	if(tabFlag=='103'){//财务出纳确认接收
			 if($.trim(onlineBankSingle)==''){
					$.ligerDialog.SQalert({content: "请填写网银制单人!",SQ_type: "warning",SQ_showButtons: true});
					return ;
			}
		}
		//封装参数
		var data={
			"id":"${fncGroupCompanyAccountVO.id}",
			"handWay":handWay,
			"postInfo":postInfo,
			"receiver":receiver,
			"postData":postData,
			"onlineBankNum":onlineBankNum,
			"onlineBankSingle":onlineBankSingle,
			"onlineBankReviewer":onlineBankReviewer
		}
		var wait_dialog = null;
		$.ajax({
			type: 'post',
			dataType: 'json',
			data: data,
			url: '<%=path%>/account/fncGroupCompanyAccount/updatePartInfo.do',
			beforeSend : function() {
				wait_dialog = $.ligerDialog.SQalert({
					content : LogUtils.LOG_CMM_DATA_LOADING,
					SQ_type : "waitting"
				});
			},
			success : function(msg) {
				wait_dialog.close();
				if (msg.success == 1) {
					//alert(msg.info);
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				} else {
					$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				wait_dialog.close();
				$.ligerDialog.SQalert({
					content : "网络错误，请稍后重试",
					SQ_type : "error"
				});
			}
		});
	}//end 
	//显示已上传但是未保存的文件列表
	function showFiles(data, index){
		var sysDate = $("#sysDate").val();
		var loginUsrNm = $("#loginUsrNm").val();
		var f_Grid = liger.get("ligergrid_file"+index);
		var uploadJOSN = data;
		for (var i=0; i< uploadJOSN.length; i++){ 
    		//添加行-追加行
    		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
		}
	}
	//保存文件
	function saveFile2(pkId){
		var docArray = JSON.stringify(getUploadResultParams(2));
        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
    	if(null == docArray){
    		//无要上传的文件-直接结束
    		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
    	}else{
	        if(pkId){//ID不为空执行
		        //赋值附件
		        var data = {
					"docArray":docArray,
					"pkId": pkId,
					"flag": "accountData"
				};
				//请求
		        AjaxUtils.ajaxPost(url, data, function(msg){
		        	if(msg.success == 1){
						 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
						 if(msg.data){
							 clearUploadResultParams(2);
						 }
					 }else{
						 UIUtils.alertError(msg.info);
					 }
		        }, true);
	        }else{
	        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
	        }
    	}
	}	
	</script>
</body>
</html>